﻿using System;
using System.Collections.Generic;
using System.Linq;
using Sustainalytics.Synchronization.Validation.ValidationRules.Common;
using Sustainalytics.Synchronization.Validation.Internals;

namespace Sustainalytics.Synchronization.Validation.ValidationRules.Core
{
    public abstract class CoreRule<T> : Rule<T>
    {
    }

    public abstract class CorePercentChangeBetween<T> : CoreRule<T>
    {
        private readonly IComparable to;
        private readonly IComparable from;

        protected CorePercentChangeBetween(IComparable from, IComparable to = null) 
        {
            this.from = from;
            this.to = to;
        }

        protected bool Validator(T validatedEntity, T referenceEntity)
        {
            var modelValue = (IComparable)GetValue(validatedEntity);
            var referenceValue = (IComparable)GetValue(referenceEntity);

            return RulesExtensions.Validator(modelValue,referenceValue,from,to);
        }
    }
}
